package org.millioncall.yueyoga.admin.export;

import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.millioncall.yueyoga.admin.model.Member;

public class MemberExportTemplate extends AbstractExcelExportTemplate {

	private List<Member> records;
	String[] titles = new String[] { "编号", "姓名", "手机号", "信息来源", "会籍顾问", "区域",
			"状态", "子状态", "负责人", "卡项", "有效期" };

	public MemberExportTemplate(List<Member> records) {
		this.records = records;
	}

	@Override
	public String[] getSheetNames() {
		return new String[] { "会员信息表" };
	}

	@Override
	public String[][] getTitles() {
		return new String[][] { titles };
	}

	@Override
	protected void buildBody(int sheetIndex) {
		Sheet sheet = getSheet(sheetIndex);
		int startIndex = this.getBodyStartIndex(sheetIndex);
		for (int i = 0; i < this.records.size(); i++) {
			Member record = this.records.get(i);

			Row row = sheet.createRow(i + startIndex);
			row.setHeight((short) 300);
			int index = 0;
			createStyledCell(row, index++, record.getCardnumber() == null ? ""
					: record.getCardnumber().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getName() == null ? ""
					: record.getName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getPhone() == null ? ""
					: record.getPhone().toString(), this.bodyRowStyle);
			String xxly = "";
			String xy = record.getMarketingsource();
			String xxy;
			if (xy == null) {
				xxy = "";
			} else {
				xxy = record.getMarketingsource().toString();
			}
			if ("81".equals(xxy)) {
				xxly = "电话打入";
			} else if ("82".equals(xxy)) {
				xxly = "主动拜访";
			} else if ("83".equals(xxy)) {
				xxly = "数据库";
			} else if ("84".equals(xxy)) {
				xxly = "线上活动";
			} else if ("85".equals(xxy)) {
				xxly = "线下活动";
			} else if ("86".equals(xxy)) {
				xxly = "其他";
			}
			createStyledCell(row, index++, xxly, this.bodyRowStyle);
			createStyledCell(row, index++, record.getKeeperName() == null ? ""
					: record.getKeeperName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getAreaName() == null ? ""
					: record.getAreaName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getMainStatus() == null ? ""
					: record.getMainStatus().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getZstatus() == null ? ""
					: record.getZstatus().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getFuzerenName() == null ? ""
					: record.getFuzerenName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getProductName() == null ? ""
					: record.getProductName().toString(), this.bodyRowStyle);
			createStyledCell(
					row,
					index++,
					record.getStringOfProductEndTime() == null ? "" : record
							.getStringOfProductEndTime(), this.bodyRowStyle);
		}
	}

	@Override
	public String[] getCaptions() {
		return new String[] { "会员信息表" };
	}
}
